﻿/************************************************************************

 This file is part of EscapeFromPrisonPlanet.

 EscapeFromPrisonPlanet is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 EscapeFromPrisonPlanet is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with Foobar.  If not, see <http://www.gnu.org/licenses/>.

************************************************************************/

// All code (c)2012 Scott Bevin. all rights reserved

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace LudumDare25Project.Objects
{
    internal class Bullet
    {
        public Vector2 Position = Vector2.Zero;
        private Texture2D sprite;
        public Vector2 Velocity;
        private Color color;
        public float Radius;

        public bool Kill = false;
        private float Speed = 1200.0f;

        public Bullet(Texture2D sprite, Vector2 pos, Vector2 target, Color color)
        {
            Position = pos;
            this.sprite = sprite;

            Velocity = target - Position;
            Velocity.Normalize();
            Velocity *= Speed;
            this.color = color;

            Radius = (float)Math.Sqrt((sprite.Width * sprite.Width) + (sprite.Height * sprite.Height));
            Radius *= 0.5f;
        }

        public void Update(float dt, float focusX)
        {
            Position += Velocity * dt;

            if (Position.X > focusX + 1000.0f)
                Kill = true;
        }

        public void Render(SpriteBatch sprites)
        {
            sprites.Draw(sprite, Position, null, color, 0.0f,
                new Vector2(sprite.Width, sprite.Height) * 0.5f, 1.0f, SpriteEffects.None, 0.0f);
        }
    }
}